package com.longge;

import java.util.PriorityQueue;

public class MaximizeSum {

    public int maximizeSum(int[] nums, int k) {
        int ans = 0;
        PriorityQueue<Integer> pq = new PriorityQueue<>((o1,o2)->o2-o1);
        for (int num : nums) {
            pq.offer(num);
        }

        while (k>0){
            Integer p = pq.poll();
            ans += p++;
            pq.offer(p);
            k--;
        }
        return ans;

    }

}
